package com.iflytek.testtoastwindow.utils;

import android.content.Context;
import android.os.Build;

import java.io.IOException;

public class RomUtil 
{
	private static final String BRAND_XIAOMI = "xiaomi";
    private static final String BRAND_HUAWEI = "huawei";
    private static final String BRAND_OPPO = "oppo";
    private static final String BRAND_VIVO = "vivo";
    private static final String BRAND_SUMSUNG = "sumsung";
	private static final String BRAND_COOLPAD = "coolpad";
	private static final String BRAND_CUHIZI = "smartisan";
	private static final String BRAND_MEIZU = "meizu";
	private static final String BRAND_LENOVO = "lenovo";

	private static PhoneType phoneType = null;
    /**
     * 获取手机类型
     * @return
     */
	public static PhoneType getPhoneType()
	{
		if(null != phoneType)
		{
			return phoneType;
		}
		String brand = Build.BRAND;
		String user = Build.USER;
		String host = Build.HOST;
		String product = Build.PRODUCT;

		if(BRAND_XIAOMI.equalsIgnoreCase(brand) || BRAND_XIAOMI.equalsIgnoreCase(user))
		{
			phoneType = PhoneType.PHONE_TYPE_XIAOMI;
		}
		if(BRAND_HUAWEI.equalsIgnoreCase(brand) || BRAND_HUAWEI.equalsIgnoreCase(user))
		{
			phoneType = PhoneType.PHONE_TYPE_HUAWEI;
		}
		if(BRAND_OPPO.equalsIgnoreCase(brand) || BRAND_OPPO.equalsIgnoreCase(user))
		{
			phoneType = PhoneType.PHONE_TYPE_OPPO;
		}
		if(BRAND_VIVO.equalsIgnoreCase(brand) || BRAND_VIVO.equalsIgnoreCase(user))
		{
			phoneType = PhoneType.PHONE_TYPE_VIVO;
		}
		if(BRAND_SUMSUNG.equalsIgnoreCase(brand) || BRAND_SUMSUNG.equalsIgnoreCase(user))
		{
			phoneType = PhoneType.PHONE_TYPE_SUMSUNG;
		}
		else if(BRAND_COOLPAD.equalsIgnoreCase(brand) || BRAND_COOLPAD.equalsIgnoreCase(user))
		{
			phoneType = PhoneType.PHONE_TYPE_COOLPAD;
		}
		else if(BRAND_CUHIZI.equalsIgnoreCase(brand) || BRAND_CUHIZI.equalsIgnoreCase(user))
		{
			phoneType = PhoneType.PHONE_TYPE_CHUIZI;
		}
		else if(BRAND_MEIZU.equalsIgnoreCase(brand) || BRAND_MEIZU.equalsIgnoreCase(user))
		{
			phoneType = PhoneType.PHONE_TYPE_MEIZU;
		}
		else if(BRAND_LENOVO.equalsIgnoreCase(brand) || BRAND_LENOVO.equalsIgnoreCase(user))
		{
			phoneType = PhoneType.PHONE_TYPE_LENOVO;
		}

		if(null == phoneType)
		{
			if(null == host)
			{
				host = "";
			}
			else
			{
				host = host.toLowerCase();
			}
			if(null == product)
			{
				product = "";
			}else
			{
				product = product.toLowerCase();
			}
			if(BRAND_XIAOMI.contains(host) || BRAND_XIAOMI.contains(product))
			{
				phoneType = PhoneType.PHONE_TYPE_XIAOMI;
			}
			if(BRAND_HUAWEI.contains(host) || BRAND_HUAWEI.contains(product))
			{
				phoneType = PhoneType.PHONE_TYPE_HUAWEI;
			}
			if(BRAND_OPPO.contains(host) || BRAND_OPPO.contains(product))
			{
				phoneType = PhoneType.PHONE_TYPE_OPPO;
			}
			if(BRAND_VIVO.contains(host) || BRAND_VIVO.contains(product))
			{
				phoneType = PhoneType.PHONE_TYPE_VIVO;
			}
			if(BRAND_SUMSUNG.contains(host) || BRAND_SUMSUNG.contains(product))
			{
				phoneType = PhoneType.PHONE_TYPE_SUMSUNG;
			}
			if(BRAND_COOLPAD.contains(host) || BRAND_COOLPAD.contains(product))
			{
				phoneType = PhoneType.PHONE_TYPE_COOLPAD;
			}
			if(BRAND_CUHIZI.contains(host) || BRAND_CUHIZI.contains(product))
			{
				phoneType = PhoneType.PHONE_TYPE_CHUIZI;
			}
			if(BRAND_MEIZU.contains(host) || BRAND_MEIZU.contains(product))
			{
				phoneType = PhoneType.PHONE_TYPE_MEIZU;
			}
			if(BRAND_LENOVO.contains(host) || BRAND_LENOVO.contains(product))
			{
				phoneType = PhoneType.PHONE_TYPE_LENOVO;
			}
		}
		if(null == phoneType)
		{
			phoneType = PhoneType.PHONE_TYPE_OTHER;
		}

		return phoneType;
	}
	
	final static String MIUI_V5 = "v5";
	final static String MIUI_V6 = "v6";
	final static String MIUI_V7 = "v7";
	final static String MIUI_V8 = "v8";
	final static String MIUI_V9 = "v9";
	
	/**
	 * 是否是miui5
	 * @param context
	 * @return
	 */
	public static boolean isMIUI5(Context context)
	{
		String result = "";
		try {
			result = BuildProperties.newInstance().getProperty("ro.miui.ui.version.name");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return MIUI_V5.equalsIgnoreCase(result);
	}
	
	/**
	 * 是否是miui6及以上
	 * @param context
	 * @return
	 */
	public static boolean isMIUI6OrHigher(Context context)
	{
		String result = "";
		try {
			result = BuildProperties.newInstance().getProperty("ro.miui.ui.version.name");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return MIUI_V6.equalsIgnoreCase(result) || MIUI_V7.equalsIgnoreCase(result) || MIUI_V8.equalsIgnoreCase(result) ||  MIUI_V9.equalsIgnoreCase(result);
	}
	
	
}
